package cn.schoolwow.workflow.test.module.option.testcase;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.workflow.QuickWorkFlow;
import cn.schoolwow.workflow.domain.deploy.WorkFlowDefinitionOption;
import cn.schoolwow.workflow.domain.instance.WorkFlowInstanceStatus;
import cn.schoolwow.workflow.test.module.analyzeWorkReport.audit.single.addBeforeSign.flow.AddBeforeSignCompleteAnalyzeWorkReportFlow;
import cn.schoolwow.workflow.test.module.analyzeWorkReport.audit.single.common.handler.AuditTestCaseFlowTryCatchFinallyHandler;

public class AddSignOptionTestCaseFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        flowContext.startFlow("测试加签选项")
                .next(new BusinessFlow() {
                    @Override
                    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
                        String deployName = flowContext.checkData("deployName", String.class);
                        QuickWorkFlow quickWorkFlow = flowContext.checkInstanceData(QuickWorkFlow.class);

                        WorkFlowDefinitionOption workFlowDefinitionOption = new WorkFlowDefinitionOption();
                        workFlowDefinitionOption.allowAdd = false;
                        quickWorkFlow.updateWorkFlowDefinitionOption(deployName, workFlowDefinitionOption);
                    }

                    @Override
                    public String name() {
                        return "更新工作流定义选项";
                    }
                })
                .next(new AddBeforeSignCompleteAnalyzeWorkReportFlow())
                .tryCatchFinallyHandler(new AuditTestCaseFlowTryCatchFinallyHandler())
                .putInstanceData(WorkFlowInstanceStatus.Finished)
                .execute();
    }

    @Override
    public String name() {
        return "允许加签选项测试用例";
    }

}
